import Message.CheckDTO;
import Message.StuMessageDTO;
import httpclient.QuickStart;
import javabean.Userbean;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import javax.json.bind.Jsonb;
import javax.json.bind.JsonbBuilder;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;


/**
 * @author liushan
 * Created by liushan on 2019-04-09.
 */
@WebServlet(urlPatterns = {"/localLogin"})
public class localLogin extends HttpServlet {

    // curl -v http://localhost:8080/test/Servlet1
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {

        doPost(req,resp);
    }



    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=UTF-8");

        String username = req.getParameter("username");
        String password = req.getParameter("password");

        Userbean user = new Userbean(username,password);
        HttpSession session = req.getSession(true);
        session.setAttribute("users",user);

        if(!user.login())
        {
            resp.sendRedirect("http://localhost:8080/Login.jsp");
        }
        else{
            resp.sendRedirect("http://localhost:8080/message.jsp");
        }
    }
}
